<template>
	<view class="goods-list-item">
		<view class="goods-list-item-left">
			<radio :checked="goods.goods_state" color="#C00000" v-if="showRadio" @click="radioChangeHandler" />
			<image :src="goods.goods_small_logo || defaultPic" class="goods-pic"></image>
		</view>
		<view class="goods-list-item-right">
			<view class="goods-name">
				{{ goods.goods_name }}
			</view>
			<view class="goods-price">
				￥{{ goods.goods_price | toFixed }}
				<uni-number-box @blur="changeNumberBox" v-if="isShowNumberBox" v-model="goods.goods_count" :min="1"
					@change="changeNumberBox"></uni-number-box>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "my-goodsList",
		props: {
			goods: {
				type: Object,
				default: {}
			},
			// 是否展示图片左侧的 radio
			showRadio: {
				type: Boolean,
				default: false
			},
			// 是否显示数字输入框
			isShowNumberBox: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				// 默认图片地址
				defaultPic: 'https://img3.doubanio.com/f/movie/8dd0c794499fe925ae2ae89ee30cd225750457b4/pics/movie/celebrity-default-medium.png'
			};
		},
		filters: {
			toFixed(num) {
				return Number(num).toFixed(2)
			}
		},
		methods: {
			radioChangeHandler() {
				this.$emit('radio-change', {
					// 商品的 Id
					goods_id: this.goods.goods_id,
					// 商品最新的勾选状态
					goods_state: !this.goods.goods_state
				})
			},
			changeNumberBox(e) {
				this.$emit('changeNumberBox', {
					goods_id: this.goods.goods_id,
					goods_count: e
				})
			}
		}
	}
</script>

<style lang="less">
	.goods-list-item {
		display: flex;
		padding: 10px 5px;
		border-bottom: 1px solid red;

		.goods-list-item-left {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-right: 5px;

			image {
				width: 100px;
				height: 100px;
			}
		}

		.goods-list-item-right {
			display: flex;
			flex-direction: column;
			justify-content: space-between;

			.goods-name {
				overflow: hidden;
				font-size: 13px;
				display: -webkit-box;
				-webkit-box-orient: vertical;
				-webkit-line-clamp: 4;
			}

			.goods-price {
				display: flex;
				justify-content: space-between;
				align-items: center;
				font-size: 16px;
				color: #c00000;
			}
		}
	}
</style>
